package com.basic;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.ConvertUtils;

import com.business.socialcredit.SocialCreditFactory;
import com.frame.struts.ActionContext;
import com.frame.struts.BaseBean;
import com.utils.CommUtil;
import com.utils.DateConverter;

public class CpzlbzForm extends BaseBean
{
    public CpzlbzForm()
    {
    }
    
    static{
        ConvertUtils.register(new DateConverter(), Date.class);
    }

    CpzlbzEntity cpzlbzEntity = new CpzlbzEntity();
    private String oldId="";

    public String addCpzlbz()
    {
        if( logger.isDebugEnabled() )
        {
            logger.debug( "enter addCpzlbz()" );
        }
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        PublicInfoFactory factory = PublicInfoFactory.getInstance();
        String qyid = (String) request.getSession()
                                      .getAttribute( "session_qyid" );
        cpzlbzEntity.setQyid( qyid );
        cpzlbzEntity.setOptdate( new Date() );
        cpzlbzEntity.setOptrid( CommUtil.getUserId( request ) );
        cpzlbzEntity.setXh( SocialCreditFactory.getNextXh( "qy_cpzlbz", qyid ) );
        try
        {
            if( factory.addCpzlbz( cpzlbzEntity ) )
            {
                System.out.println( "Enter addCpzlbz()" );
                response.sendRedirect( "/publicinfo/querycpzlbz.jsp" );
            }else{
                response.sendRedirect( "/failed.jsp" );
            }
        }
        catch( Exception e )
        {
        }
        return null;

    }

    public String editCpzlbz()
    {
        if( logger.isDebugEnabled() )
        {
            logger.debug( "enter addCpzlbz()" );
        }
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        PublicInfoFactory factory = PublicInfoFactory.getInstance();
        String qyid = (String) request.getSession()
                                      .getAttribute( "session_qyid" );
        cpzlbzEntity.setQyid( qyid );
        cpzlbzEntity.setOptdate( new Date() );
        cpzlbzEntity.setOptrid( CommUtil.getUserId( request ) );
        factory.delCpzlbz(qyid,cpzlbzEntity.getXh());
        try
        {
            if( factory.addCpzlbz( cpzlbzEntity ) )
            {
                System.out.println( "Enter editCpzlbz()" );
                response.sendRedirect( "/publicinfo/querycpzlbz.jsp" );
            }else{
                response.sendRedirect( "/failed.jsp" );
            }
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        return null;
    }
    
    public String getOldId(){
        return this.oldId;
    }
    public void setOldId(String oldId){
        this.oldId=oldId;
    }
    
    public String getQyid()
    {
        return cpzlbzEntity.getQyid();
    }

    public void setQyid( String qyid )
    {
        cpzlbzEntity.setQyid(qyid);
    }

    public int getXh()
    {
        return cpzlbzEntity.getXh();
    }

    public void setXh( int xh )
    {
        cpzlbzEntity.setXh( xh );
    }

    
    public String getOptrid()
    {
        return cpzlbzEntity.getOptrid();
    }

    public void setOptrid( String optrid )
    {
        cpzlbzEntity.setOptrid( optrid );
    }

    public Date getOptdate()
    {
        return cpzlbzEntity.getOptdate();
    }

    public void setOptdate( Date optdate )
    {
        cpzlbzEntity.setOptdate( optdate );
    }

    public String getRecstate()
    {
        return cpzlbzEntity.getRecstate();
    }

    public void setRecstate( String recstate )
    {
        cpzlbzEntity.setRecstate( recstate );
    }

    public String getRemark()
    {
        return cpzlbzEntity.getRemark();
    }

    public void setRemark( String remark )
    {
        cpzlbzEntity.setRemark( remark );
    }
    
    public String getGycpmc()
    {
        return cpzlbzEntity.getGycpmc();
    }
    public void setGycpmc( String gycpmc )
    {
        cpzlbzEntity.setGycpmc( gycpmc );
    }
    public String getJcjl()
    {
        return cpzlbzEntity.getJcjl();
    }
    public void setJcjl( String jcjl )
    {
        cpzlbzEntity.setJcjl( jcjl );
    }
    public String getXhgg()
    {
        return cpzlbzEntity.getXhgg();
    }
    public void setXhgg( String xhgg )
    {
        cpzlbzEntity.setXhgg( xhgg );
    }
    public String getYxq()
    {
        return cpzlbzEntity.getYxq();
    }
    public void setYxq( String yxq )
    {
        cpzlbzEntity.setYxq( yxq );
    }
    
    public String getZlbz()
    {
        return cpzlbzEntity.getZlbz();
    }
    public void setZlbz( String zlbz )
    {
        cpzlbzEntity.setZlbz( zlbz );
    } 
}
